/**
 * @param arr 数组对象
 * @param parent 是否只获取父一层的属性
 * @description 递归获取需要的数据
 */
interface dataObj {
  key: string,
  title: string,
  children:[]
}

 export function getTreeKey(arr:dataObj[], parent = false) {
  const dataList:{key:string,title:string}[] = [];
  const generateList = (data:dataObj[]) => {
    for (let i = 0; i < data.length; i++) {
      const { key, title, children } = data[i];
      if (!parent) dataList.push({ key, title });
      if (Array.isArray(children) && children.length > 0) {
        if (parent) dataList.push({ key, title });
        generateList(children);
      }
    }
  };
  generateList(arr);
  return dataList.map(item => item.key);
}
